﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using OnlineCourse.Model.Entity;


namespace OnlineCourse.Model.EntityConfiguration
{
    public class UserConfiguration : IEntityTypeConfiguration<User>
    {
        public void Configure(EntityTypeBuilder<User> builder)
        {
            builder.Property(a => a.Id).HasDefaultValueSql("newid()");
            builder.Property(a => a.UserName).HasMaxLength(50).IsRequired();//指定字段长度，并且指定他不能为null
            builder.Property(a => a.Password).HasMaxLength(50).IsRequired();

            builder.HasIndex(a => a.UserName).IsUnique();//给username做个索引，并且制定username是非主键的唯一字段

            builder.Property(a => a.Account).HasColumnType("decimal(18,6)");
        }
    }
}
